<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        /* 遮罩层样式 */
        .overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色 */
            z-index: 1000; /* 确保遮罩层在最顶层 */
        }
        /* 登录弹窗样式 */
        .login-popup {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            padding: 20px;
            z-index: 1001; /* 比遮罩层高一层 */
        }
    </style>
</head>
<body>

<button onclick="openLoginPopup()">打开登录弹窗</button>

<div class="overlay" id="overlay"></div>

<div class="login-popup" id="loginPopup">
    <h2>登录</h2>
    <button onclick="closeLoginPopup()">关闭</button>
</div>

<script>
    function openLoginPopup() {
        document.getElementById('overlay').style.display = 'block';
        document.getElementById('loginPopup').style.display = 'block';
        document.body.style.overflow = 'hidden'; // 禁止页面滚动
    }

    function closeLoginPopup() {
        document.getElementById('overlay').style.display = 'none';
        document.getElementById('loginPopup').style.display = 'none';
        document.body.style.overflow = 'auto'; // 恢复页面滚动
    }


</script>

</body>
</html>
